<?php
use yii\helpers\Url;
?>
<div class="row-content am-cf">
<div class="row">

    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
        <div class="widget am-cf">
            <div class="widget-head am-cf">
                <div class="widget-title am-fl">新增操作员</div>
                <div class="widget-function am-fr">
                    <a href="javascript:;" class="am-icon-cog"></a>
                </div>
            </div>
            <div class="widget-body am-fr">

                <form class="am-form tpl-form-border-form tpl-form-border-br">
                    <div class="am-form-group">
                        <label for="user-name" class="am-u-sm-3 am-form-label">用户名 </label>
                        <div class="am-u-sm-9">
                            <input type="text" class="tpl-form-input" id="username" placeholder="请输入用户名">

                        </div>
                    </div>

                    <div class="am-form-group">
                        <label for="user-email" class="am-u-sm-3 am-form-label">密码 </label>
                        <div class="am-u-sm-9">
                            <input type="text" class="tpl-form-input" id="password" placeholder="请输入密码">

                        </div>
                    </div>

                    <div class="am-form-group">
                        <label for="user-phone" class="am-u-sm-3 am-form-label">区域 </label>
                        <div class="am-u-sm-9">
                            <select data-am-selected="{searchBox: 0}" id="area" style="display: none;">
                                <?php foreach ($areas as $area) {
                                    echo "<option value=\"".$area['id']."\">".$area['areaname']."</option>";
                                }?>

                            </select>

                        </div>
                    </div>

                    <div class="am-form-group">
                        <label class="am-u-sm-3 am-form-label">姓名 </label>
                        <div class="am-u-sm-9">
                            <input type="text" id="realname" placeholder="输入姓名">
                        </div>
                    </div>


                    <div class="am-form-group">
                        <label for="user-weibo" class="am-u-sm-3 am-form-label">联系电话 </label>
                        <div class="am-u-sm-9">
                            <input type="tel" id="phone" placeholder="请输入电话">
                            <div>

                            </div>
                        </div>
                    </div>



                    <div class="am-form-group">
                        <div class="am-u-sm-9 am-u-sm-push-3">
                            <button id="submit" type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success ">提交</button>
                        </div>
                    </div>
                </form>
                <script>
                    $("#submit").click(function(){
                        var username= $("#username").val();
                        var password=$("#password").val();
                        var realname = $("#realname").val();
                        var phone = $("#phone").val();
                        var areaid=$("#area").val();
                        if(username==''){
                            alert("用户名不能为空！");
                            return ;
                        }
                        if(password==''){
                            alert("密码不能为空！");
                            return ;
                        }
                        if(realname==''){
                            alert("姓名不能为空！");
                            return ;
                        }
                        if(!checkPhone(phone)){
                            alert("手机号不正确！");
                            return ;
                        }
                        $.ajax({
                            url:"<?=Url::to(['user/add-operator'])?>",
                            data:"username="+username+"&password="+password+"&areaid="+areaid+"&realname="+realname+"&phone="+phone,
                            type:'post',
                            dataType:'json',
                            success:function(data){
                                if(data.status){
                                    alert("新增成功");
                                    window.location.href="<?=Url::to(['user/operator-list'])?>";
                                }else{
                                    alert(data.msg);
                                }
                            },
                            error:function(){
                                alert("系统繁忙");
                            }
                        })
                    })

                </script>
            </div>
        </div>
    </div>
</div>
</div>